const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: 'dist/tab-communication.min.js',
          to: 'D:/wwwroot/test.com/tab-communication.min.js',
          force: true,
        },
      ],
    }),
  ],
  entry: './src/index.ts',
  mode: 'production',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: 'tab-communication.min.js',
    path: path.resolve(__dirname, 'dist'),
    library: 'TabCommunication',
    libraryTarget: 'umd',
    globalObject: 'this'
  },
  optimization: {
    minimize: true,
    // minimizer: [new TerserPlugin({
    //   terserOptions: {
    //     compress: {
    //       drop_console: false,
    //     },
    //   },
    // })],
  },
};